package com.imy.alscript;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.imy.alscript.models.AppInfo;

import java.util.List;

public class ListAdapter extends BaseSimpleListAdapter<AppInfo, ListAdapter.Holder> {
  private Context mContext;
  private List mList;

  public ListAdapter(Context context, List<AppInfo> infos) {
    super(context, infos);
  }

  @Override
  protected void bindView(int position, Holder holder, View convertView, AppInfo bean) {
    Drawable icon = bean.icon;
    if (icon!=null){
      holder.icon.setImageDrawable(icon);
      holder.icon.setVisibility(View.VISIBLE);
    }else {
      holder.icon.setVisibility(View.INVISIBLE);
    }
    holder.nameTv.setText(bean.name);
    holder.packageTv.setText(bean.packageName);
    if (bean.isMode){
      holder.modeTv.setVisibility(View.VISIBLE);
    }else {
      holder.modeTv.setVisibility(View.INVISIBLE);
    }
  }

  @Override
  protected int getLayoutId() {
    return R.layout.list_item;
  }

  @Override
  public Holder getHolder(View view) {
    return new Holder(view);
  }

  public class Holder extends BaseViewHolder{

    TextView nameTv;
    ImageView icon;
    TextView packageTv;
    TextView modeTv;
    public Holder(View itemView) {
      super(itemView);
      nameTv =itemView.findViewById(R.id.apk_name);
      icon =itemView.findViewById(R.id.icon_iv);
      packageTv =itemView.findViewById(R.id.package_tv);
      modeTv =itemView.findViewById(R.id.item_mode_tv);
    }
  }
}
